<template>
  <el-dialog :visible="showOperationDialog" title="批量策略管理" @close="btnCancel">
    <el-form ref="policy" label-width="120px">
      <el-form-item label="选择策略：">
        <el-select v-model="formData.policyId" placeholder="请选择" style="width:80%" @focus="getPolicyList">
          <el-option v-for="(value,index) in policyList" :key="index" :label="value.policyName" :value="value.policyId" />
        </el-select>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-row type="flex" justify="center">
        <el-col :span="8">
          <el-button @click="btnCancel">取消</el-button>
          <el-button type="warning" @click="btnOK">确认</el-button>
        </el-col>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { getPolicyList, applyPolicy } from '@/api/policy'
export default {
  props: {
    showOperationDialog: {
      type: Boolean,
      default: false
    },
    selectVal: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      policyList: [],
      formData: {
        innerCodeList: [],
        policyId: ''
      }
    }
  },
  methods: {
    async getPolicyList() {
      const { data } = await getPolicyList()
      this.policyList = data
    },
    async btnOK() {
      this.selectVal.forEach(item => {
        this.formData.innerCodeList.push(item.innerCode)
      })
      await applyPolicy(this.formData)
      this.$emit('update:showOperationDialog', false)
      this.$emit('editEquipment')
      this.$message.success('修改成功')
    },
    btnCancel() {
      this.formData = {
        innerCodeList: [],
        policyId: ''
      }
      this.$emit('update:showOperationDialog', false)
    }

  }
}
</script>

<style>

</style>
